<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/common/taglibs.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
	<%@ include file="/common/common-css.jsp" %>
	<script>
	</script>
		
	<style>
		.table > th {
		  vertical-align: center;
		  background-color: grey;
	}
	</style>		
</head>
<body class="no-skin">
	<div class="page-content">
			<div class="page-header">
				<h1>
					编辑主界面Banner信息
				</h1>
			
			</div>
		<div class="page-content-area">
			<div class="row">
				<div class="col-xs-12 col-sm-12 widget-container-col">
					<div class="widget-box widget-color-blue">
						<!-- #section:custom/widget-box.options.collapsed -->
						<div class="widget-header widget-header-small">
							<h6 class="widget-title lighter">
								<i class="ace-icon glyphicon glyphicon-th-list"></i>基本信息
							</h6>
                            <div class="widget-toolbar no-border">
								<a href="#" data-action="collapse">
									<i class="ace-icon fa fa-chevron-up"></i>
								</a>
							</div>
						</div>
						
						<div class="widget-body">
							<div class="widget-main" >
								<form class="form-horizontal" id="validation-form" method="post" enctype="multipart/form-data">
									<input type="text" hidden="hidden" id="id" name ="id" value="${paramsMap.id}">
									<input type="text" hidden="hidden" id="status" name ="status" value="${paramsMap.status}">
									<input type="text" hidden="hidden" id="msg" name ="msg" value="${paramsMap.msg}">
									<input type="text" hidden="hidden" id="type" name ="type" value="${paramsMap.type}">
									<table id="baseinfo" class="table table-bordered table-striped table-hover table-condensed table-responsive table">
										<tr>
											<th>渠道</th>
											<td colspan="3">
												<s:select name="channel" list="%{paramsMap.channelList}" listKey="code" listValue="name" cssClass="form-control" value="%{paramsMap.channel}" ></s:select>
											</td>
											<th>平台</th>
											<td colspan="3">
												<s:select name="platform" list="%{paramsMap.platformList}" listKey="code" listValue="name" cssClass="form-control" value="%{paramsMap.platform}" ></s:select>
											</td>
										</tr>
										<tr>
											<th>过滤渠道</th>
											<td colspan="4">
												<input type="text" name="except_channel" id="except_channel" class="col-xs-12 col-sm-12" value="${paramsMap.except_channel}">
											</td>
											<td colspan="3"><font style="color: red">填写渠道ID，多个渠道以,隔开</font></td>
										</tr>
										<tr>
											<th>产品</th>
											<td colspan="3">
												<%-- <s:select name="product" list="%{paramsMap.productlist}" listKey="code" listValue="name" cssClass="form-control" value="%{paramsMap.product}" ></s:select> --%>
												<s:iterator id="oo" value="%{paramsMap.productlist}" var="var"> 
													<p><input type="checkbox" class="category" name="category" value="<s:property value='#var.code'/>" /><s:property value='#var.name'/> </p>  
												</s:iterator>
											</td>
											<th>备注</th>
											<td colspan="3">
												<input type="text" name="memo" id="memo" class="col-xs-12 col-sm-12" value="${paramsMap.memo}">
											</td>
										</tr>
										<tr>
											<th>最小版本号</th>
											<td colspan="3">
												<input type="text" name="minVersionCode" id="minVersionCode" class="col-xs-12 col-sm-12" value="${paramsMap.minVersionCode}" >
											</td>
											<th>最大版本号</th>
											<td colspan="3">
												<input type="text" name="maxVersionCode" id="maxVersionCode" class="col-xs-12 col-sm-12" value="${paramsMap.maxVersionCode}">
											</td>
										</tr>
										<tr>
											<th>开始时间</th>
											<td colspan="3">
												<input type="text" data-date-format="yyyy-mm-dd hh:ii:ss" class="endDate date-picker input-sm form-control" style="padding-left:0px" name="startTime" id="startTime" value="${paramsMap.startTime}">
											</td>
											<th>结束时间</th>
											<td colspan="3">
												<input type="text" data-date-format="yyyy-mm-dd hh:ii:ss" class="endDate date-picker input-sm form-control" style="padding-left:0px" name="endTime" id="startTime" value="${paramsMap.endTime}" >
											</td>
										</tr>
										<tr>
										    <th><span class="red">*</span>位置</th>
											<td colspan="3">
												<input type="text" name="position" id="position" class="col-xs-12 col-sm-12" value="${paramsMap.position}">
											</td> 
											<th><span class="red">*</span>顺序</th>
											<td colspan="3">
												<input type="text" name="orderNum" id="orderNum" placeholder="" class="col-xs-12 col-sm-12" value="${paramsMap.orderNum}">
											</td>
										</tr>
										<tr>
											<th><span class="red">*</span>标题</th>
											<td colspan="3">
												<input type="text" name="title" id="title" class="col-xs-12 col-sm-12" value="${paramsMap.title}">
											</td>
											<th><span class="red">*</span>内容</th>
											<td colspan="3">
												<input type="text" name="content" id="content" placeholder="" class="col-xs-12 col-sm-12" value="${paramsMap.content}">
											</td>
										</tr>
										<tr>
											<th>显示方式</th>
											<td colspan="3">
												<s:select name="displayWay" list="%{paramsMap.displayWayList}" listKey="code" listValue="name" 
														cssClass="form-control" value="%{paramsMap.displayWay}" /> 
											</td>
											<th id="cache_title">缓存记录</th>
											<td colspan="3" id="cache_content">
												<input type="text" name="api" id="api" class="col-xs-12 col-sm-12" value="${paramsMap.api}">
											</td>
										</tr>
										<tr>
											<th><span class="red">*</span>跳转链接</th>
											<td colspan="3">
												<input type="text" name="targetUrl" id="targetUrl" class="col-xs-12 col-sm-12" value="${paramsMap.targetUrl}">
											</td>
											<th>打开跳转的方式</th>
											<td colspan="3">
												<s:select id="launch" name="launch" list="%{paramsMap.launchParamList}" listKey="memo" listValue="kindname"
													cssClass="form-control" value="%{paramsMap.launch}"/> 
											</td>
										</tr>
										<tr>
											<th><span class="red">*</span>跳转标题</th>
											<td colspan="3">
												<input type="text" name="targetTitle" id="targetTitle" class="col-xs-12 col-sm-12" value="${paramsMap.targetTitle}">
											</td>
											<th>展示方式</th>
											<td colspan="3">
												<s:select name="showType" list="%{paramsMap.showTypeList}" listKey="code" listValue="kindname"
															cssClass="form-control" value="%{paramsMap.showType}" /> 
											</td>
										</tr>
										<tr>
											<th>是否需要登录</th>
											<td colspan="3">
												<s:select name="mustLogin" list="%{paramsMap.loginList}" listKey="code" listValue="name"
															cssClass="form-control" value="%{paramsMap.mustLogin}" /> 
											</td>
										</tr>
										<tr>
											<th>是否开启沉浸式</th>
											<td colspan="3">
												<s:select name="isTitleBarImmerse" list="%{paramsMap.isList}" listKey="code" listValue="name"
														  cssClass="form-control" value="%{paramsMap.isTitleBarImmerse}" />
											</td>
											<th>是否开启我的图标白色</th>
											<td colspan="3">
												<s:select name="isMyIconWhite" list="%{paramsMap.isList}" listKey="code" listValue="name"
														  cssClass="form-control" value="%{paramsMap.isMyIconWhite}" />
											</td>
										</tr>
										<tr>
											<th>销毁原界面</th>
											<td>
												<input type="checkbox" name="clearTop" id="clearTop" >
											</td>
											<th>限制网络图片加载</th>
											<td>
												<input type="checkbox" name="canBlockNetworkImg" id="canBlockNetworkImg" >
											</td>
											<th>登录重新加载</th>
											<td>
												<input type="checkbox" name="reloadWhenLogin" id="reloadWhenLogin" >
											</td>
											<th>html页面接管返回键的处理</th>
											<td>
												<input type="checkbox" name="takeOverBackPressed" id="takeOverBackPressed" >
											</td>
										</tr>
										<tr>
											<th>resume和pause时回调页面</th>
											<td>
												<input type="checkbox" name="callbackWhenResumeAndPause" id="callbackWhenResumeAndPause" >
											</td>
											<th>显示标题栏</th>
											<td>
												<input type="checkbox" name="showTitle" id="showTitle" >
											</td>
											<th>注入xmiles_inject.css</th>
											<td>
												<input type="checkbox" name="injectCss" id="injectCss" >
											</td>
										</tr>
											<tr id="persist_time_container">
											<th>启动页广告播放时间</th>
											<td>
												<input type="text" name="persist_time" id="persist_time" class="col-xs-12 col-sm-12" value="${paramsMap.persist_time}">
											</td>
										</tr>
										<tr>
											<th>带协议头</th>
											<td>
												<input type="checkbox" name="withHead" id="withHead">
											</td>
											<th>显示工具栏</th>
											<td>
												<input type="checkbox" name="showToolbar" id="showToolbar">
											</td>
										</tr>
										<tr>
											<th>推送城市（用『生成城市id』生成的）</th>
											<td colspan="7">
												<input type="text" name="cityids" id="cityids" class="col-xs-12 col-sm-12" value="${paramsMap.cityids}">
											</td>
										</tr>
										<tr>
											<th>自定义LaunchParam</th>
											<td colspan="7">
												<input type="text" name="diy_launch_param" id="diy_launch_param" class="col-xs-12 col-sm-12" value="${paramsMap.diy_launch_param}">
											</td>
										</tr>
										<tr>
											<th>额外常用信息</th>
											<td colspan="7">
												<input type="text" name="extra" id="extra" class="col-xs-12 col-sm-12" value="${paramsMap.extra}">
											</td>
										</tr>
										<tr>
											<th>替换条件</th>
											<td colspan="3">
												<s:select name="conditonType" list="%{paramsMap.bannerConditionList}" listKey="code" listValue="name" 
														cssClass="form-control" value="%{paramsMap.conditonType}" /> 
											</td>
											<th>替换值</th>
											<td colspan="3" id="conditonValue">
												<input type="text" name="conditonValue" id="conditonValue" class="col-xs-12 col-sm-12" value="${paramsMap.conditonValue}">
											</td>
										</tr>
										<tr>
											<th>替补banner主键</th>
											<td colspan="7">
												<input type="text" name="bannerId" id="bannerId" class="col-xs-12 col-sm-12" value="${paramsMap.bannerId}">
											</td>
										</tr>
									</table>
									<p>
									 <img id="preimg" name="preimg" src="http://img.xmiles.cn/img/void.png"/>
									 <input type="text" hidden="hidden" id="oldimg" name ="oldimg" value="">
									 <input id="upload" name="upload" class="form-control" type="file" title="上传图片"/>
									</p>
									<p>
										<span class="red">标题图片：</span>
										<img id="titleUrlView" name="titleUrlView" src="http://img.xmiles.cn/img/void.png"/>
										<input type="text" hidden="hidden" id="titleUrl" name ="titleUrl" value="">
										<input id="upload_titleUrl" name="uploadTitleUrl" class="form-control" type="file" title="上传图片"/>
									</p>
									<h3 style="color: red" id="errorMsg"></h3>
								</form>
							</div><!-- /.widget-main -->
						</div><!-- /.widget-body -->
					</div><!-- /.widget-box -->
				</div><!-- /.col-sm-12 -->
			</div><!-- /.row -->
		
				
				<div class="clearfix form-actions">
					<div class="col-md-offset-3 col-md-9">
						<button id="btn-cancel" class="btn  btn-inverse  no-border " onclick="doCancle()" id="delete"> 
							<i class="ace-icon fa fa-undo bigger-160"></i>
							取消
						</button>
		
						&nbsp; &nbsp; &nbsp;
						<button id="btn-save" name="btn-save" class="btn  btn-success  no-border" type="button" onclick="doSave()">
							<i class="ace-icon fa fa-floppy-o bigger-160"></i>
							保存
						</button>
					</div>
				</div>
			</div>
		</div>
<%@ include file="/common/common-js.jsp" %>
<script>

var app_prd_id = getQueryString('app_prd_id'); 
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
 	var r = window.location.search.substr(1).match(reg);
	if (r != null) return decodeURI(r[2]); return null;	
}

jQuery(function($) {
	 if(!app_prd_id || app_prd_id == 'null'){
		 $(".category[value='9999']").attr('checked','true');
	  }else{
		  var str = app_prd_id.split("SPLIT");
		  for(i = 0 ; i < str.length; i++){
			  $(".category[value='" + str[i] + "']").attr('checked','true');
		  } 
	  }
	
	 $(".category[value='9999']").click(function () { 
		 if($(".category[value='9999']").is(':checked')){
			 $(".category").each(function(){
		         $(this).attr('disabled',true); 
		         if($(this).val() != "9999"){
		        	 $(this).attr('checked',false); 
		         }
		     });
			 $(".category[value='9999']").attr('checked',true);
			 $(".category[value='9999']").attr('disabled',false);
		 }else{
			 $(".category").each(function(){
		         $(this).attr('disabled',false); 
		     });
		 }
	});  
	 
	if($(".category[value='9999']").is(':checked')){
		$(".category").each(function(){
		$(this).attr('disabled',true); 
		if($(this).val() != "9999"){
		     $(this).attr('checked',false); 
		 }
		});
		$(".category[value='9999']").attr('checked',true);
		$(".category[value='9999']").attr('disabled',false);
	}
	$("#channel").combobox();
	
	// 新增时默认打开全屏Web页面打开
	if($.isBlank($("#targetUrl").val()) && $.isBlank($("#targetTitle").val())){
	   $("#launch option[value='launch_vc_webView']").attr("selected","selected");
	}
});

//时间控件
jQuery(function($) {
	$(".date-picker").datetimepicker({autoclose:true}).next().on(ace.click_event, function(){
		$(this).prev().focus();
	});
	
});
jQuery(function($){
	var img = "${paramsMap.imgurl}";
	if(img != null && img != ""){
		$("#preimg").attr("src",img);
		$('#oldimg').attr("value",img);
	}

    var titleUrl = "${paramsMap.titleUrl}"
    if (titleUrl != null && titleUrl != ""){
        $("#titleUrlView").attr("src",titleUrl);
        $('#titleUrl').attr("value",titleUrl);
    }
	var type = ${paramsMap.type};
	/* if(type != 1 && type != 15 && type != 18 && type != 22){
		$("#position").attr("value",1);
		$("#position").attr("hidden","hidden");
	} */
	// 播放时间只有11启动页广告才有
	if (type !== 11) {
		$("#persist_time_container").hide();
	} else {
		// 如果数据库没有值，默认就3秒
		var persist_time = "${paramsMap.persist_time}";
		if (persist_time === null || persist_time  === "" 
			|| persist_time  === "null" || parseInt(persist_time) <= 0) {
			$("#persist_time").attr('value', 3);
		}
	}
	var withHead = ${paramsMap.withHead};
	if(withHead == 1){
		$("#withHead").attr("checked","checked");
	}
	var showToolbar = ${paramsMap.showToolbar};
	if(showToolbar == 1){
		$("#showToolbar").attr("checked","checked");
	}
	var clearTop = ${paramsMap.clearTop};
	if(clearTop == 1){
		$("#clearTop").attr("checked","checked");
	}
	var canBlockNetworkImg = ${paramsMap.canBlockNetworkImg};
	if(canBlockNetworkImg == 1){
		$("#canBlockNetworkImg").attr("checked","checked");
	}
	var reloadWhenLogin = ${paramsMap.reloadWhenLogin};
	if(reloadWhenLogin == 1){
		$("#reloadWhenLogin").attr("checked","checked");
	}
	var takeOverBackPressed = ${paramsMap.takeOverBackPressed};
	if(takeOverBackPressed == 1){
		$("#takeOverBackPressed").attr("checked","checked");
	}
	var callbackWhenResumeAndPause = ${paramsMap.callbackWhenResumeAndPause};
	if(callbackWhenResumeAndPause == 1){
		$("#callbackWhenResumeAndPause").attr("checked","checked");
	}
	var showTitle = ${paramsMap.showTitle};
	if(showTitle == 1){
		$("#showTitle").attr("checked","checked");
	}
	var injectCss = ${paramsMap.injectCss};
	if(injectCss == 1){
		$("#injectCss").attr("checked","checked");
	}
	var status = $("#status").attr("value");
	var msg = $("#msg").attr("value");
	if(status == 1){
		 parent.parent['__extdialog_active'].dialog('close');
	}else if(status == -1){
		$("#errorMsg").text($("#msg").attr("value"));
	}
	
	if($("#displayWay").val() == 4){
		$("#cache_title").html("老用户时间");
		$("#api").attr("data-date-format", "yyyy-mm-dd hh:ii:ss");
		$("#api").attr("class", "endDate date-picker input-sm form-control");
		$(".date-picker").datetimepicker({autoclose:true}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});
	}else if($("#displayWay").val() == 5){
		$("#cache_title").html("点击次数");
	}else if($("#displayWay").val() == 6){
		$("#cache_title").html("新用户间隔指定时间数");
	}
	
	$("#displayWay").bind("change", function () { 
		var diaplay = $(this).val();
		if(diaplay == 4){
			$("#cache_title").html("老用户时间");
			$("#api").attr("data-date-format", "yyyy-mm-dd hh:ii:ss");
			$("#api").attr("class", "endDate date-picker input-sm form-control");
		}else if($("#displayWay").val() == 5){
			$("#cache_title").html("点击次数");
			$("#api").removeAttr("data-date-format");
			$("#api").attr("class", "col-xs-12 col-sm-12");
			$("#api").val("");
		}else if($("#displayWay").val() == 6){
			$("#cache_title").html("新用户间隔指定时间数");
			$("#api").val("");
		}else{
			$("#cache_title").html("缓存记录");
			$("#api").removeAttr("data-date-format");
			$("#api").attr("class", "col-xs-12 col-sm-12");	
			$("#api").val("");
		}
		$(".date-picker").datetimepicker({autoclose:true}).next().on(ace.click_event, function(){
			$(this).prev().focus();
		});
	});
	
});
$('#upload').change(function(){
	var file = this.files[0];
	var r = new FileReader();
	r.readAsDataURL(file);
	$(r).load(function(){
	$('#preimg').attr('src',this.result);
	});
});
$('#upload_titleUrl').change(function(){
    var file = this.files[0];
    var r = new FileReader();
    r.readAsDataURL(file);
    $(r).load(function(){
        $('#titleUrlView').attr('src',this.result);
    });
});
function doSave(){
	$("#btn-save").attr("disabled","disabled");
	var $form = document.forms["validation-form"];
	$form.action = ctx + "/mainbanner/saveBase.action";
	$form.submit();
}

function doCancle(){
	 parent.parent['__extdialog_active'].dialog('close');
}
</script>	
</body>
</html>
